import java.util.ArrayList;



public class MusicBuffer {

	
	ArrayList<MusicalEvent> list;
	
	
	
	
	public static void run() {
		
		MusicBuffer mb = new MusicBuffer();
		mb.pushEvent(0,60,100,0,100);
		
		mb.pushEvent(0,61,100,0,200);
	
		mb.pushEvent(0,62,100,0,300);
		
		mb.pushEvent(0,63,100,0,400);

	for(int i=0;i<mb.list.size();i++)
		System.out.println(mb.list.get(i).note);

		System.out.println("**");
		mb.popEvent();
		mb.popEvent();
	
		for(int i=0;i<mb.list.size();i++)
			System.out.println(mb.list.get(i).note);
		
		
		
	}
	
public MusicBuffer() {
		
		list= new ArrayList<MusicalEvent>();
	}
	
	
	public synchronized boolean pushEvent(int t, int n, int v, int c, int d)
	{
		
		try
		{
			MusicalEvent newme= new MusicalEvent(t,n,v,c,d);
			list.add(newme);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}
	public synchronized MusicalEvent popEvent() {
		
		try
		{
			if(!list.isEmpty())
				{
			
				
				return list.remove(0);		
				}
			
			else return null;
		}
		catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
		
		

		

	}
	
	
}
